import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/',
    name: 'Main',
    component: () => import('../views/pages/Main'),
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('../views/pages/home/Home.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path: 'programme',
        name: 'Programme',
        component: () => import('../views/pages/programme/Programme'),
        meta: {
          title: '集成方案'
        }
      },
      {
        path: '/file',
        name: 'File',
        component: () => import('../views/pages/file/File'),
        meta: {
          title: '文档中心'
        }
      },
      {
        path: '/debug',
        name: 'Debug',
        component: () => import('../views/pages/file/components/debug/Debug'),
        meta: {
          title: '在线调试'
        }
      },
      {
        path: 'download',
        name: 'Download',
        component: () => import('../views/pages/download/Download'),
        meta: {
          title: '下载中心'
        }
      },
      {
        path: 'regsiter',
        name: 'Regsiter',
        component: () => import('../views/pages/register/Register'),
        meta: {
          title: '注册'
        }
      },
      {
        path: 'login',
        name: 'Login',
        component: () => import('../views/pages/login/Login'),
        meta: {
          title: '登录'
        }
      },
      {
        path: 'modify',
        name: 'modifyPassword',
        component: () => import('../views/pages/modifyPassword/modifyPassword'),
        meta: {
          title: '找回密码'
        }
      },
      {
        path: 'authentication',
        name: 'Authentication',
        component: () => import('../views/pages/authentication/Authentication'),
        meta: {
          title: '实名认证'
        }
      }
    ]
  },
  {
    path: '/console',
    name: 'Console',
    component: () => import('../views/pages/console/Console'),
    redirect: '/console/consoleHome',
    children: [
      {
        path: '/console/enterprise',
        name: 'consoleHome',
        component: () => import('../views/pages/console/components/enterprise/Enterprise'),
        meta: {
          title: '企业信息'
        }
      },
      {
        path: '/console/consoleHome',
        name: 'consoleHome',
        component: () => import('../views/pages/console/components/home/consoleHome'),
        meta: {
          title: '控制台首页'
        }
      },
      {
        path: '/console/apply',
        name: 'apply',
        component: () => import('../views/pages/console/components/apply/Apply'),
        meta: {
          title: '我的应用'
        }
      },
      {
        path: '/console/user',
        name: 'user',
        component: () => import('../views/pages/console/components/user/User'),
        redirect: '/console/user/mine',
        meta: {
          title: '用户管理'
        },
        children: [
          {
            path: '/console/user/mine',
            name: 'Mine',
            component: () => import('../views/pages/console/components/mine/Mine'),
            meta: {
              title: '个人用户'
            }
          },
          {
            path: '/console/user/firm',
            name: 'firm',
            component: () => import('../views/pages/console/components/firm/Firm'),
            meta: {
              title: '企业用户'
            }
          }
        ]
      },
      {
        path: '/console/seal',
        name: 'Seal',
        component: () => import('../views/pages/console/components/seal/Seal'),
        meta: {
          title: '印章管理'
        }
      },
      {
        path: '/console/template',
        name: 'template',
        component: () => import('../views/pages/console/components/template/Template'),
        meta: {
          title: '模板管理'
        }
      },
      {
        path: '/console/sign',
        name: 'sign',
        component: () => import('../views/pages/console/components/sign/Sign'),
        meta: {
          title: '签署管理'
        }
      },
      {
        path: '/console/checking',
        name: 'checking',
        component: () => import('../views/pages/console/components/checking/Checking'),
        meta: {
          title: '验签管理'
        }
      },
      {
        path: '/console/contract',
        name: 'contract',
        component: () => import('../views/pages/console/components/contract/Contract'),
        meta: {
          title: '合同管理'
        }
      }
    ]
  }
]

// 解决新版本router多次点击出错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  routes,
  originalPush
  // // 滚动行为
  // scrollBehavior(to, from, savedPosition) {
  //   if (savedPosition) {
  //     return savedPosition
  //   } else {
  //     return {
  //       x: 0,
  //       y: 0
  //     }
  //   }
  // }
})

export default router
